<template>
  <wd-button @click="toShow">提交</wd-button>
	<wd-button @click="isRunning">是否在运行</wd-button>
	<wd-button @click="destroy">注销</wd-button>
	<wd-button @click="restart">重启</wd-button>
	<wd-button @click="jingyin">停止声音</wd-button>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
// import { startWallPaper } from "@/uni_modules/wd-wallpaper"

const keepAlive = uni.requireNativePlugin('Ba-KeepAlive')
const jnWallpaper = uni.requireNativePlugin('jc-Wallpaper')

const channelId = ref('Ba-KeepAlive'), channelName = ref('Ba-KeepAlive'), title = ref('Ba-KeepAlive'), content = ref('Ba-KeepAlive is running'), dataResult = ref(''), type = ref(undefined)

onMounted(() => {
	// myApi({
		
	// })
})
const toShow = () => {
	// #ifndef H5
	// 判断当前环境是否为安卓
	if (plus.os.name.toLowerCase() === "android") {
		// keepAlive.whiteList({
		// 	whiteType: 4
		// });
		// keepAlive.register({
		// 		channelId: channelId.value,
		// 		channelName: channelName.value,
		// 		title: title.value,
		// 		content: content.value,
		// 		backgroundMusicEnabled: true
		// },
		// (res) => {
		// 		let audio = uni.getBackgroundAudioManager();
		// 		audio.src = 'https://yonganpicture.oss-cn-shenzhen.aliyuncs.com/-2444988082738836260.MP4';
		// 		audio.play();
		// 		audio.onEnded( () => {
		// 			console.log('播放结束')
		// 			audio.play()
		// 		} )
		// 		uni.showToast({
		// 				title: res.msg,
		// 				icon: "none",
		// 				duration: 3000
		// 		})
		// });
		uni.chooseVideo({
		    compressed:false,
		    sourceType: ['album'],
		    success: function(res) {
		        console.log(plus.io.convertLocalFileSystemURL(res.tempFilePath ) ,'res-----')
		        jnWallpaper.setDynamicWallpaper({
		            url:plus.io.convertLocalFileSystemURL(res.tempFilePath )
		        })
		    }
		});
		// let audio = uni.getBackgroundAudioManager();
		// audio.src = 'https://yonganpicture.oss-cn-shenzhen.aliyuncs.com/-2444988082738836260.MP4';
		// audio.play();
		// audio.onEnded( () => {
		// 	console.log('播放结束')
		// } )
		// startWallPaper({
  //     url: 'https://yonganpicture.oss-cn-shenzhen.aliyuncs.com/-2444988082738836260.MP4',
  //     complete: (res) => {
  //       console.log(res)
  //     }
  //   });
		// var WallpaperManager = plus.android.importClass(
		// 	"android.app.WallpaperManager"
		// );
		// var WallpaperManagerService = plus.android.importClass(
		// 	"android.service.wallpaper.WallpaperService"
		// )
		// var Main = plus.android.runtimeMainActivity();
		// var wallpaperManager = WallpaperManager.getInstance(Main);
	}	
		// #endif
}
const isRunning = () => {
	keepAlive.isRunning((res) => {
			console.log(res);
			uni.showToast({
					title: res.msg,
					icon: "none",
					duration: 3000
			})
	});
}
const destroy = () => {
	keepAlive.unregister((res) => {
		console.log(res);
		uni.showToast({
				title: res.msg,
				icon: "none",
				duration: 3000
		})
	});
}
const restart = () => {
	keepAlive.restart((res) => {
			console.log(res);
			uni.showToast({
					title: res.msg,
					icon: "none",
					duration: 3000
			})
	});
}
const jingyin = () => {
	jnWallpaper.setVolume({
	    bl: false //true 开启 false 关闭
	})
}
</script>

<style scoped lang="scss">

</style>